package com.jinbei.restController;

import com.jinbei.common.annotation.EncryptMethod;
import com.jinbei.common.base.BaseRedisService;
import com.jinbei.common.base.ResponseBase;
import com.jinbei.common.base.ResponseBaseEntity;
import com.jinbei.domain.Message;
import com.jinbei.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by lucky on 2018/7/10.
 */
@RestController
public class TestController {

    @Autowired
    private BaseRedisService redisService;
    @Autowired
    private MessageService messageService;

    @EncryptMethod(isEncrypt = true)
    @PostMapping("/encrypt")
    @ResponseBody
    public ResponseBase queryEncrypt(@RequestBody Map<String,String> map , @RequestParam("encrypt") String encrypt){
        try {
            return  ResponseBaseEntity.setResultSuccess(map);
        }catch (Exception e){
            e.printStackTrace();
            return  ResponseBaseEntity.setResultError(null);
        }
    }

    @RequestMapping("/socket")
    public String login(@RequestParam("data") String data,
                        @RequestParam("title") String title,
                        @RequestParam("uid") String uid){
        try {
            Message message = new Message();
            message.setContent(data);
            message.setTitle(title);
            message.setType("system");
            messageService.insertMessage(message,uid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }

    @RequestMapping("/addRedis")
    public String addRedis(){
        redisService.set("liuxin","123456",60*5*1000);
        return "success";
    }

    @RequestMapping("/getRedis")
    public String getRedis(){
        String liuxin = (String) redisService.get("liuxin");
        return liuxin;
    }
}
